package xiaohuo.fancyring.data

import eos.moe.dragoncore.api.worldtexture.WorldTexture
import taboolib.library.configuration.ConfigurationSection
import taboolib.module.configuration.util.getStringColored
import taboolib.module.configuration.util.getStringListColored
import xiaohuo.fancyring.config.ConfigManager

class RingData(config: ConfigurationSection) {
    val lore = config.getStringColored("Lore")!!

    val position = ConfigManager.positionMap[config.getString("Position")]!!

    private val scale = config.getDouble("Scale").toFloat()

    val executeOp =
        config.getStringListColored("Execute").filter { it.startsWith("[OP]") }.map { it.replace("[OP]", "") }
    val executeConsole =
        config.getStringListColored("Execute").filter { it.startsWith("[Console]") }.map { it.replace("[Console]", "") }

    val texture = WorldTexture().apply {
        path = config.getString("Texture")
        animationList.addAll(config.getStringList("Animation").mapNotNull { ConfigManager.animationMap[it] })
        followEntityDirection = true
    }

    fun applyPosition(level: Int) {
        with(texture) {
            translateX = position.x + level * position.xIncrease
            translateY = position.y + level * position.yIncrease
            translateZ = position.z + level * position.zIncrease
            rotateX = position.rotateX
            rotateY = position.rotateY
            rotateZ = position.rotateZ
            translateEntityRight = position.front + level * position.frontIncrease
            translateEntityFront = position.right + level * position.rightIncrease
            val finalScale = scale + (ConfigManager.scaleIncrease[level] ?: 0F)
            width = finalScale
            height = finalScale
        }
    }
}